************************************************************************************************************************
** Replication file for: "From Confidence to Convenience: Changes in Voting Systems, Donald Trump, and Voter Confidence"
** last updated June 6, 2024
** uses data files archived at: https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/C03Y9B

************************************************************************************************************************

**install these packages from the SSC archive if not previously installed
* ssc install fre
* ssc install revrs
* ssc install outreg2 
* ssc install blindschemes

** edit the next line to indicate file path where data files are located and output will be saved
cd "/Users/jqm5/Dropbox (Personal)/Confidence to Convenience/Drafts/Public Opinion Quarterly/Replication Files/"

log using "Log file for Confidence Replication do File.log", replace 

********** Table 2: Confidence in Ballot and Satisfaction with Method 
** 2006 Utah exit poll 
use "2006 STATA Data.dta", clear
tab confacc  [aweight=nweight]

** 2008 Utah exit poll
use "2008 STATA Data.dta", clear
tab confacc [aweight=nwgt]
tab votesat [aweight=nwgt]

**2018 Utah election survey 
use "2018 Full Dataset 8.28.23 weighted anonymized.dta", clear
tab confident_w2 [aweight=actual_voter_weights_trimmed]
tab method_w2 [aweight=actual_voter_weights_trimmed]

**2020 Utah election survey - everything looks good 
use "2020 Full Dataset 8.28.23 weighted anonymized.dta", clear
tab s_confident [aweight=actual_voter_weights_trimmed]
tab s_method [aweight=actual_voter_weights_trimmed]


**********Table 3: Models of Voter Confidence  
****2018 Utah election survey variables****  
use "2018 Full Dataset 8.28.23 weighted anonymized.dta", clear

** Dependent Variable is the confidence the respondents had that votes were counted accurately 
** We reverse coded the dep variable so that higher numbers indicate higher confidence 
revrs confident_w2
rename revconfident_w2 revconfacc18
tab revconfacc18
tab revconfacc18, nolabel
*sample size is 942 

** Independent Variables
** We renamed and coded indpendent variables so that variable names and coding are consistent across both 2018 and 2020 models

*Male 
tab GENDER_w2
tab GENDER_w2, nolabel
gen Male=GENDER_w2
tab Male
recode Male (2 3=0)
tab Male GENDER_w2

* 5 Category Party ID. 1 is Strong Democrat, 2 is Other Democrat, 3 is Independent, 4 is Other Republican, 5 is Strong Republican
fre PARTYIDSINGLE_w2 PARTYIDBRANCH_w2 LEAN_w2 INTENSE_w2
gen pid5=.
replace pid5=1 if PARTYIDSINGLE_w2==1
replace pid5=1 if PARTYIDBRANCH_w2==2 & INTENSE_w2==1
replace pid5=2 if PARTYIDSINGLE_w2==2 | PARTYIDSINGLE_w2==3
replace pid5=2 if PARTYIDBRANCH_w2==2 & INTENSE_w2==2
replace pid5=2 if PARTYIDBRANCH_w2==3 & LEAN_w2==2
replace pid5=3 if PARTYIDSINGLE_w2==4
replace pid5=3 if PARTYIDBRANCH_w2==3 & LEAN_w2==4
replace pid5=4 if PARTYIDSINGLE_w2==5 | PARTYIDSINGLE_w2==6
replace pid5=4 if PARTYIDBRANCH_w2==1 & INTENSE_w2==2
replace pid5=4 if PARTYIDBRANCH_w2==3 & LEAN_w2==1
replace pid5=5 if PARTYIDBRANCH_w2==1 & INTENSE_w2==1
replace pid5=5 if PARTYIDSINGLE_w2==7

label define pid5 1 "Strong Democrat" 2"Other Democrat" 3"Independent" 4"Other Republican" 5"Strong Republican"
label values pid5 pid5
fre pid5 [aweight=weights_trimmed]
tab pid5 PARTYIDSINGLE_w2
tab pid5 PARTYIDBRANCH_w2

* Ideology 
fre IDEOLOGY
gen ideo5=IDEOLOGY
recode ideo5 (6 7=3)
label define ideo5 1 "St Lib" 2"M Lib" 3"Neither/Mid/Ot/DK" 4"Mod Con" 5"St Con" 
label values ideo5 ideo5
fre ideo5

* Nonwhite 
replace NonWhite=.
replace NonWhite=0 if ETHNICITY==5
replace NonWhite=1 if ETHNICITY!=5 & ETHNICITY!=.
tab NonWhite ETHNICITY

* Married 
gen Married=.
replace Married=1 if MARITAL_STATUS==1
replace Married=0 if MARITAL_STATUS!=1 & MARITAL_STATUS!=.
tab Married MARITAL_STATUS

* Education
fre EDUCATION
gen Education=EDUCATION
recode Education (1 2=1)(3=2)(4=3)(5=4)
tab Education EDUCATION

* Trump Vote 
fre PRESIDENTAIL_RECAL
gen TrumpVoter=.
replace TrumpVoter=0 if PRESIDENTAIL_RECAL==2 | PRESIDENTAIL_RECAL==3 | PRESIDENTAIL_RECAL==4 | PRESIDENTAIL_RECAL==5
replace TrumpVoter=1 if PRESIDENTAIL_RECAL==1
fre TrumpVoter
tab TrumpVoter PRESIDENTAIL_RECAL

* County 
fre CountyGroup
rename CountyGroup County
**recode Cache County with "other" category
recode County (1=7)
fre County 

* Income 
rename INCOME Income

* one VBM experience variable renamed for main model used in Table 3
rename VBMCountEvenYears12to18 VBMCount


**** Table 3, models for columns 1-3 (2018)
*Runs the regressions and saves the results in a text file using outreg2  
regress revconfacc18 VBMCount, r
outreg2 using Table3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) replace

regress revconfacc18 VBMCount i.TrumpVoter ib3.pid5 Income Education Male NonWhite ib3.County, r
outreg2 using Table3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append

regress revconfacc18 c.VBMCount##i.TrumpVoter ib3.pid5 Income Education Male NonWhite ib3.County, r
outreg2 using Table3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append

***Figure 1, panel 1 (2018)
set scheme plotplain
margins, dydx(VBMCount) at (TrumpVoter=(0 1)) 
margins TrumpVoter, at(VBMCount=(0(1)4))
marginsplot, x(VBMCount) ylabel (1(1)4) ytitle("Confidence") xtitle("VBM Count") title("2018") scheme(plotplain) plot2opts(lpattern(dash)) legend(order(3 "Non Trump Voters" 4 "Trump Voters"))	

**********************Online Supplementary Appendix Tables for 2018 data**********************
***some of the outreg2 commands in this section require Stata SE to produce correctly 


***Table S1: Summary Stats for Variables in Table 3
regress revconfacc18 VBMCount i.TrumpVoter ib3.pid5 Income Education Male NonWhite ib3.County, r

outreg2 using TableS1.doc if e(sample), replace sum(detail) keep(revconfacc18 VBMCount pid5 Income Education Male NonWhite) eqkeep(N min max mean)  


***Table S2: Models of Confidence in Vote Count using Different VBM Counts 2018
**Model 1 in Table S2 is same as Model 1 in Table 3
regress revconfacc18 VBMCount, r
outreg2 using TableS2.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) replace

regress revconfacc18 VBMCount12to18, r
outreg2 using TableS2.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append

regress revconfacc18 VBMCountEvenYears08to18, r
outreg2 using TableS2.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append

regress revconfacc18 VBMCount08to18, r 
outreg2 using TableS2.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append


***Table S4: Summary Stats for Table S2

regress revconfacc18 VBMCount, r
outreg2 using TableS4.doc if e(sample), replace sum(detail) keep(revconfacc18 VBMCount VBMCount12to18 VBMCountEvenYears08to18  VBMCount08to18) eqkeep(N min max mean)



**********Table 3: Models of Voter Confidence  
****2020 Utah election survey variables****  

use "2020 Full Dataset 8.28.23 weighted anonymized.dta", clear

*Dependent variable 
rename s_confident confacc21
revrs confacc21
fre revconfacc21
tab revconfacc21 [aweight=actual_voter_weights_trimmed]

*Independent variable
rename s_pres presidential_vote
rename s_method voter_method
rename s_gender gender
rename s_ideology ideology
rename s_income Income

*5 Category Party ID. 
gen pid5=.
replace pid5=1 if s_party==2 & s_intesne==1
replace pid5=2 if s_party==2 & s_intesne==2
replace pid5=2 if s_party==3 & s_lean==2
replace pid5=2 if s_party==4 & s_lean==2
replace pid5=3 if s_party==3 & s_lean==3
replace pid5=3 if s_party==4 & s_lean==3
replace pid5=4 if s_party==1 & s_intesne==2
replace pid5=4 if s_party==3 & s_lean==1
replace pid5=4 if s_party==4 & s_lean==1
replace pid5=5 if s_party==1 & s_intesne==1

replace pid5=1 if s_party_updated==2 & s_intesne==1
replace pid5=2 if s_party_updated==2 & s_intesne==2
replace pid5=2 if s_party_updated==3 & s_lean==2
replace pid5=2 if s_party_updated==6 & s_lean==2
replace pid5=3 if s_party_updated==3 & s_lean==3
replace pid5=3 if s_party_updated==6 & s_lean==3
replace pid5=4 if s_party_updated==1 & s_intesne==2
replace pid5=4 if s_party_updated==3 & s_lean==1
replace pid5=4 if s_party_updated==6 & s_lean==1
replace pid5=5 if s_party_updated==1 & s_intesne==1


label define pid5 1 "Strong Democrat" 2"Other Democrat" 3"Independent" 4"Other Republican" 5"Strong Republican"
label values pid5 pid5
fre pid5 

*Male 
fre gender 
gen Male=gender
recode Male (2 3=0)
tab Male gender

*County
encode CountyGroup_voterweight, generate (County)
fre County
***recoding to match the 2018 survey coding and so that the counties go in the same order in the regression tables for both years.
recode County (4=3)(5=4)(6=5)(7=6)(3=7)(1=7)
label define County 2"DAVIS"3"SALT LAKE"4"UTAH"5"WASHINGTON"6"WEBER"7"Other" , replace
label values County County
fre County

*Education
gen Education=s_edu
recode Education (1 2=1)(3=2)(4=3)(5=4)(6=2)
label define Education 1 "HS grad or less" 2"some college/vocational" 3"college grad" 4 "post grad"
label values Education Education
fre Education 
tab Education s_edu

*Nonwhite 
fre s_race
gen NonWhite=.
replace NonWhite=0 if s_race==1
replace NonWhite=1 if s_race!=1 & s_race!=.
tab NonWhite s_race
fre NonWhite

*Trump vote 
fre presidential_vote
gen TrumpVoter=.
replace TrumpVoter=0 if presidential_vote==1 | presidential_vote==3 | presidential_vote==4
replace TrumpVoter=1 if presidential_vote==2
fre TrumpVoter
tab TrumpVoter [aweight=actual_voter_weights_trimmed]
tab TrumpVoter presidential_vote

*VBM experience 
rename OverallByMailEvenYearGens14to20 VBMCount
sum VBMCount


**** Table 3, models for columns 4-6 (2020)
***Run the regression and save the results in the same outreg file as the 2018 data  
regress revconfacc21 VBMCount, r
outreg2 using Table3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append

regress revconfacc21 VBMCount i.TrumpVoter ib3.pid5 Income Education Male NonWhite ib3.County, r 
outreg2 using Table3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append

regress revconfacc21 c.VBMCount##i.TrumpVoter ib3.pid5 Income Education Male NonWhite ib3.County, r
outreg2 using Table3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append



***Figure 1, panel 1 (2020)
set scheme plotplain 

margins, dydx(VBMCount) at (TrumpVoter=(0 1)) 

margins TrumpVoter, at(VBMCount=(0(1)4))

marginsplot, x(VBMCount) ylabel (1(1)4) ytitle("Confidence") xtitle("VBM Count") title("2020") plot2opts(lpattern(dash)) legend(order(3 "Non Trump Voters" 4 "Trump Voters"))


**********************Online Supplementary Appendix Tables for 2020 data**********************
***some of the outreg2 commands in this section require Stata SE to produce correctly 


***Table S1: Summary Stats for Variables in Table 3 for 2020
regress revconfacc21 VBMCount i.TrumpVoter ib3.pid5 Income Education Male NonWhite ib3.County, r
outreg2 using TableS1.doc if e(sample), append sum(detail) keep(revconfacc21 VBMCount pid5 Income Education Male NonWhite) eqkeep(N min max mean)  


***Table S3: Models of Confidence in Vote Count using Different VBM Counts 2020
**Model 1 in Table S3 is same as Model 4 in Table 3
regress revconfacc21 VBMCount, r
outreg2 using TableS3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) replace

regress revconfacc21 OverallByMailVotedCount14to20, r
outreg2 using TableS3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append

regress revconfacc21 OverallByMailEvenYearGens12to20, r
outreg2 using TableS3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append

regress revconfacc21 OverallByMailVotedCount12to20, r 
outreg2 using TableS3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append

regress revconfacc21 OverallByMailEvenYearGens10to20, r 
outreg2 using TableS3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append

regress revconfacc21 OverallByMailVotedCount10to20, r 
outreg2 using TableS3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append

regress revconfacc21 OverallByMailEvenYearGens08to20, r 
outreg2 using TableS3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append

regress revconfacc21 OverallByMailVotedCount08to20, r 
outreg2 using TableS3.doc, rdec(2) noaster bdec(2) sdec(2) pdec(3) stats(coef se pval) append


***Table S5: Summary Stats for Table S3

regress revconfacc21 VBMCount, r
outreg2 using TableS5.doc if e(sample), replace sum(detail) keep(revconfacc21 OverallByMailVotedCount08to20 OverallByMailVotedCount10to20 OverallByMailVotedCount12to20 OverallByMailVotedCount14to20 OverallByMailEvenYearGens08to20 OverallByMailEvenYearGens10to20 OverallByMailEvenYearGens12to20 VBMCount) eqkeep(N min max mean) 

log close

